package cn.itsource.shiro.utils;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;


/**
 * 自定义认证匹配方式，需要在shiro的xml中配置生效
 */
public class MyHashedCredentialsMatcher extends HashedCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        MyUsernamePasswordToken myToken = (MyUsernamePasswordToken)token;
        //免密登录
        if (myToken.getLoginType().equals(LoginType.NOPASSWD)){
            return true;
        }
        //密码登录
        if (myToken.getLoginType().equals(LoginType.PASSWORD)){
            return super.doCredentialsMatch(token, info);
        } else {
            return false;
        }

    }
}
